#pragma semicolon 1
#pragma newdecls required
#include <sourcemod>
#include <sdktools>
#include <sdkhooks>
#include <left4dhooks>



#define PLUGIN_NAME                   "l4d2_weapon_Speed_zombie"    //这里写插件名字
#define PLUGIN_AUTHOR                 "豆瓣酱な"                         //作者
#define PLUGIN_DESCRIPTION            "霰弹枪击飞 TANK 插件."   //介绍
#define PLUGIN_VERSION                "1.0"
#define PLUGIN_URL                    "https://gitee.com/sweet-and-sour-bombs"  //网站

public Plugin myinfo =
{
    name        = PLUGIN_NAME,
    author      = PLUGIN_AUTHOR,
    description = PLUGIN_DESCRIPTION,
    version     = PLUGIN_VERSION,
    url         = PLUGIN_URL
}

public void OnPluginStart()
{


	HookEvent("player_hurt",			Event_PlayerHurt, EventHookMode_Pre);  //玩家受伤事件
}




public void Event_PlayerHurt(Event event, const char[] name, bool dontBroadcast)
{
	char weapon[64];
	int client = GetClientOfUserId(event.GetInt("userid"));
	event.GetString("weapon", weapon, sizeof(weapon));
	if (IsTank(client))
	{
		//int slot = -1, clipsize;
		if (StrEqual(weapon, "pumpshotgun") || StrEqual(weapon, "shotgun_chrome"))
		{
			AddVelocity(client, 200.0, 500.0); //这里改击飞高度.第一个参数200.0表示水平速度为200，第二个参数500.0表示垂直速度为500
		}
		else if (StrEqual(weapon, "autoshotgun") || StrEqual(weapon, "shotgun_spas"))
		{
			AddVelocity(client, 200.0, 500.0); //这里改击飞高度.第一个参数200.0表示水平速度为200，第二个参数500.0表示垂直速度为500
		}


	}
}


public void AddVelocity(int client, float xSpeed, float zSpeed)
{

	
	float vecVelocity[3];
	//GetEntDataVector(client, g_iVelocity, vecVelocity);
	
	if(GetRandomInt(0, 1))
	{
		vecVelocity[0] -= xSpeed;
	}
	else
	{
		vecVelocity[0] += xSpeed;
	}
	
	if(GetRandomInt(0, 1))
	{
		vecVelocity[1] -= xSpeed;
	}
	else
	{
		vecVelocity[1] += xSpeed;
	}
	vecVelocity[2] += zSpeed;
	
	TeleportEntity(client, NULL_VECTOR, NULL_VECTOR, vecVelocity);

}





bool IsInfected(int client)
{
	return client > 0 && client <= MaxClients && IsClientInGame(client) && GetClientTeam(client) == 3;
}

bool IsTank(int client)  
{
	if (!IsInfected(client))
		return false;

	if (GetEntProp(client, Prop_Send, "m_zombieClass") != 8)
		return false;

	return true;
}
